package com.luyu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.luyu.entity.Unit;
import com.luyu.mapper.UnitMapper;
import com.luyu.service.IUnitService;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-10-18
 */
@Service
public class UnitServiceImpl implements IUnitService {
    @Resource
    @Lazy
    private Uservice uservice;

    @Override
    public List<Long> listIdsByParentUnitId(Long unitId) {
        if (unitId == null) {
            return new ArrayList<>();
        }
        List<Unit> list = uservice.lambdaQuery()
                .select(Unit::getId)
                .eq(Unit::getId, unitId)
                .or()
                .eq(Unit::getParentUnitId, unitId)
                .list();
        return list
                .stream()
                .map(Unit::getId)
                .collect(Collectors.toList());
    }

    @Component
    public static class Uservice extends ServiceImpl<UnitMapper, Unit> {


    }


}
